package com.acme.bankapp.domain.bank;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import com.acme.bankapp.exceptions.bank.ClientExistsException;
import com.acme.bankapp.exceptions.bank.NotEnoughFundsException;
import com.acme.bankapp.exceptions.bank.OverDraftLimitExceededException;

import static com.acme.bankapp.service.bank.BankService.addAccount;
import static com.acme.bankapp.service.bank.BankService.addClient;

public class BankApplication {
	
	public static void modifyBank(Bank bank, int idOfClient, String depositOrWithdraw, 
			int numOfAccount, int sum) throws NotEnoughFundsException, IllegalArgumentException{
		
		ArrayList<Client> clients = bank.getClients();
		if(!(depositOrWithdraw.equals("deposit") || depositOrWithdraw.equals("withdraw")) 
				|| clients.size() < idOfClient + 1){
			throw new IllegalArgumentException("IllegalArgumentException");
		}
		else if(clients.get(idOfClient).getAccounts().size() < numOfAccount + 1){
			throw new IllegalArgumentException("IllegalArgumentException");
		}
		else{
			if(depositOrWithdraw.equals("deposit")){
				clients.get(idOfClient).getAccounts().get(numOfAccount).deposit(sum);
			}
			else if(depositOrWithdraw.equals("withdraw"))
				clients.get(idOfClient).getAccounts().get(numOfAccount).withdraw(sum);
		}
	}
	
	public void printBalance(Bank b){
		ArrayList<Client> clients = b.getClients();
		for (Client cl : clients){
			ArrayList<Account> accounts = cl.getAccounts();
			for(Account ac : accounts){
				cl.getClientSalutation();
				System.out.println(" " + ac.getBalance());
			}			
		}
	}
	
	public static void main(String[] args){
		try{
			Bank b = new Bank();
			addClient(b, new Client("Ivanov", Gender.MALE, 100, 10));
			addClient(b, new Client("Ivanov", Gender.FEMALE, 100, 10));
			addAccount(b, 0, 300);
			modifyBank(b, 0, "withdraw", 0, 500);
			modifyBank(b, 0, "withdraw", 1, 500);

		}catch(IllegalArgumentException e){
			e.printStackTrace();
		}catch(ClientExistsException e){
			e.printStackTrace();
		}catch(OverDraftLimitExceededException e){
			e.outputPrint();
			e.printStackTrace();
		}catch(NotEnoughFundsException e){
			e.outputPrint();
			e.printStackTrace();
		}finally {
		}

	}
}
